package cn.edu.hust.sse.software7.class3.serviceImpl;

import java.util.List;
import java.util.logging.Logger;

import cn.edu.hust.sse.software7.class3.DAO.EBCategoryDAO;
import cn.edu.hust.sse.software7.class3.entities.EBCategory;
import cn.edu.hust.sse.software7.class3.service.EBCategoryService;

public class EBCategoryServiceImpl implements EBCategoryService {
	private static Logger log;
	EBCategoryDAO dao = new EBCategoryDAO();

	public EBCategoryServiceImpl() {
		if (dao == null) {
			dao = new EBCategoryDAO();
		}
		log = Logger.getLogger(EBCategoryServiceImpl.class.getName());
	}

	@Override
	public boolean isExistCategory(EBCategory category) {
		return dao.isExistCategory(category);
	}

	@Override
	public void addCategory(EBCategory category) {
		boolean checkCategory = dao.isExistCategory(category);
		if (!checkCategory) {
			dao.addCategory(category);
		} else {
			log.info("category with the name of " + category.getCategoryName()
					+ "is already exist.");
		}
	}

	@Override
	public void deleteCategory(EBCategory category) {
		boolean checkExist = dao.isExistCategory(category);
		if (checkExist) {
			dao.deleteCategory(category);
		} else {
			log.info("category with the name of " + category.getCategoryName()
					+ "is not exist as all.");
		}
	}

	@Override
	public void deleteAllCategory(List<EBCategory> categories) {
		if(!categories.isEmpty()){
			dao.deleteAllCategory(categories);
		}
	}

	@Override
	public List<EBCategory> getCategories() {
		return dao.getCategories();
	}

	@Override
	public EBCategory getCategoryById(Long categoryId) {
		return dao.getCategoryById(categoryId);
	}

	@Override
	public List<EBCategory> getCategoriesByPid(Long parentCId) {
		return dao.getCategoriesByPid(parentCId);
	}

	@Override
	public void deleteCategoryById(Long categoryId) {
		dao.deleteCategoryById(categoryId);
		
	}

}
